Product Code Database
Example Keywords: slippers -linux $71-197
barcode-scavenger
   » » Wiki: Spaghetti Code
Tag Wiki 'Spaghetti Code'.
Tag

Spaghetti code is a phrase for difficult-to-maintain and unstructured . Code being developed with poor structure can be due to any of several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insufficient ability or experience.


Meaning
Code that overuses statements rather than structured programming constructs, resulting in convoluted and unmaintainable programs, is often called spaghetti code. Such code has a complex and tangled control structure, resulting in a program flow that is conceptually like a bowl of spaghetti, twisted and tangled.
(2025). 9780470181607, J. Wiley & Sons.

In a 1980 publication by the United States National Bureau of Standards, the phrase spaghetti program was used to describe older programs having "fragmented and scattered files".

Spaghetti code can also describe an in which object-oriented code is written in a procedural style, such as by creating classes whose methods are overly long and messy, or forsaking object-oriented concepts like polymorphism. The presence of this form of spaghetti code can significantly reduce the comprehensibility of a system.

(2025). 9781612842592


History
It is not clear when the phrase spaghetti code came into common usage; however, a references appeared in 1972 including The principal motivation behind eliminating the goto statement is the hope that the resulting programs will not look like a bowl of spaghetti. by Martin Hopkins.Hopkins, M. E. (1972): A Case fo the GOTO. In: ACM ' Https://dl.acm.org/doi/10.1145/800194.805860< /ref> In the 1978 book A primer on disciplined programming using PL/I, PL/CS, and PL/CT, Richard Conway described programs that "have the same clean logical structure as a plate of spaghetti",
(1978). 9780876267127, Winthrop Publishers.
a phrase repeated in the 1979 book An Introduction to Programming he co-authored with .
(1979). 9780316154147, Little, Brown.
In the 1988 paper A spiral model of software development and enhancement, the term is used to describe the older practice of the code and fix model, which lacked planning and eventually led to the development of the . In the 1979 book Structured programming for the COBOL programmer, author Paul Noll uses the phrases spaghetti code and rat's nest as synonyms to describe poorly structured source code.

In the Ada – Europe '93 conference, Ada was described as forcing the programmer to "produce understandable, instead of spaghetti code", because of its restrictive exception propagation mechanism.

In a 1981 computer languages spoof in The Michigan Technic titled "BASICally speaking...FORTRAN bytes!!", the author described stating that "it consists entirely of spaghetti code".

described in his lectures

(1996). 9789056995003, Taylor & Francis.
the etymology of the term in the context of early programming in binary codes:


Related phrases

Ravioli code
code is a term specific to object-oriented programming. It describes code that comprises well-structured classes that are easy to understand in isolation, but difficult to understand as a whole.


Lasagna code
code refers to code whose layers are so complicated and intertwined that making a change in one layer would necessitate changes in all other layers.


Examples
Here follows what would be considered a trivial example of spaghetti code in BASIC. The program prints each of the numbers 1 to 100 to the screen along with its square. Indentation is not used to differentiate the various actions performed by the code, and the program's [[GOTO|Goto]] statements create a reliance on . The flow of execution from one area to another is harder to predict. Real-world occurrences of spaghetti code are more complex and can add greatly to a program's maintenance costs.

1 i=0 2 i=i+1 3 PRINT i;"squared=";i*i 4 IF i>=100 THEN GOTO 6 5 GOTO 2 6 PRINT "Program Completed." 7 END

Here is the same code written in a structured programming style:

1 FOR i=1 TO 100 2 PRINT i;"squared=";i*i 3 NEXT i 4 PRINT "Program Completed." 5 END

The program jumps from one area to another, but this jumping is formal and more easily predictable, because and provide whereas the goto statement encourages arbitrary flow control. Though this example is small, real world programs are composed of many lines of code and are difficult to maintain when written in a spaghetti code fashion.

Here is another example of spaghetti code with embedded GOTO statements.

 INPUT "How many numbers should be sorted? "; T
 DIM n(T)
 FOR i = 1 TO T
   PRINT "NUMBER:"; i
   INPUT n(i)
 NEXT i
 'Calculations:
 C = T
     
E180:
 C = INT(C / 2)
 IF C = 0 THEN GOTO C330
 D = T - C
 E = 1
     
I220:
 f = E
     
F230:
 g = f + C
 IF n(f) > n(g) THEN SWAP n(f), n(g)
 f = f - C
 IF f > 0 THEN GOTO F230
 E = E + 1
 IF E > D THEN GOTO E180
 GOTO I220
     
C330:
 PRINT "The sorted list is"
 FOR i = 1 TO T
   PRINT n(i)
 NEXT i
     


See also
  • Big ball of mud, a piece of software with no perceivable architecture
  • International Obfuscated C Code Contest, a competition to produce pleasingly obscure C code
  • The Elements of Programming Style


External links

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs
1s Time